<?PHP
/*
 * $Id: ReflectionAnntationTest.class.php 158 2009-12-16 15:59:29Z namba0219 $
 * =============================================================================
 * Barge - Web application framework on PHP5
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * =============================================================================
 * For more information, see http://barge.googlecode.com/
 */
namespace barge;

use \Exception;
use \UnitTestCase;
use \Reflector;
use \ReflectionClass;

use barge\Annotation;
use barge\ReflectionAnntation;

/**
 * @see UnitTestCase
 */
class ReflectionAnntationTest extends UnitTestCase
{
	/**
	 * @test
	 */
	public function testGetClassAnnotations()
	{
		$annotaion = new ReflectionAnnotation('barge\_TestClass');
		$list = $annotaion->getClassAnnotations('barge\_ClassAnnotation');
		$this->assertEqual($list->size(), 1);
		$this->assertEqual($list->get(0)->name(), 'ab"c');
		$this->assertEqual($list->get(0)->value(), 1);
	}

	/**
	 * @test
	 */
	public function testGetPropertyAnnotations()
	{
		$annotaion = new ReflectionAnnotation('barge\_TestClass');
		$list = $annotaion->getPropertyAnnotations('name', 'barge\_PropertyAnnotation');
		$this->assertEqual($list->size(), 1);
		$this->assertEqual($list->get(0)->access(), true);
		// サブクラスを指定しても取得できるか
		$list = $annotaion->getPropertyAnnotations('age', 'barge\_PropertyAnnotation');
		$this->assertEqual($list->size(), 1);
		$this->assertEqual($list->get(0)->access(), false);
		// 取得できないケース
		$list = $annotaion->getPropertyAnnotations('age', 'barge\_MethodAnnotation');
		$this->assertEqual($list->size(), 0);
	}

	/**
	 * @test
	 */
	public function testGetMethodAnnotations()
	{
		$annotaion = new ReflectionAnnotation('barge\_TestClass');
		$list = $annotaion->getMethodAnnotations('getName', 'barge\_MethodAnnotation');
		$this->assertEqual($list->size(), 1);
	}

}

/**
 * @version 1.0 2009/11/03
 * @author Namba (Kenji)
 * @~barge\_ClassAnnotation(value=1, name="ab\"c")
 */
class _TestClass
{
	/**
	 * @var string
	 * @~barge\_PropertyAnnotation(access=true)
	 */
	private $name;

	/**
	 * @var string
	 * @~barge\_PropertyAnnotationEx(access=false)
	 */
	private $age;

	/**
	 * @param mixed $parameter
	 * @return int
	 * @~barge\_MethodAnnotation()
	 */
	public function getName($parameter)
	{
		return 0;
	}
}

interface _ClassAnnotation
{
	public function value();
	public function name();
}

interface _MethodAnnotation
{

}

interface _PropertyAnnotation
{
	public function access();
}

interface _PropertyAnnotationEx extends _PropertyAnnotation
{

}

